﻿using System;
using System.Windows.Forms;
using 售后客户管理.Forms;

namespace 售后客户管理
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Forms.InternalSetting.FmSQLConfig fmSQLConfig = new Forms.InternalSetting.FmSQLConfig(ConfigCode.Main);
            //if ConfigPath is not exists,show config form view
            if (!System.IO.File.Exists(ModelLibrary.AppSet.ConfigPath))
            {
                fmSQLConfig.ShowDialog();
            }
            //if config form close and cancel,exist the program
            if (fmSQLConfig.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            configs = Common.XmlHelper.XmlDeserializeFromFile<ModelLibrary.Configs>(ModelLibrary.AppSet.ConfigPath, ModelLibrary.AppSet.Encodings);
            ModelLibrary.SqlConfig sqlConfig=new ModelLibrary.SqlConfig();

            Common.SqlConnectionHelper sqlConnectionHelper = new Common.SqlConnectionHelper(configs,ConfigCode.Main);
            //if sqlconfig is disconnected, show config form view
            if (!sqlConnectionHelper.testLinks())
            {
                fmSQLConfig.ShowDialog();
            }
            if (fmSQLConfig.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            //sqlConnString = Common.SqlHelper.getConnectString(configs.sqlConfig);
            Application.Run(new FmMain());
        }
        
        public static ModelLibrary.Configs configs = new ModelLibrary.Configs();
    }
}
